import { _decorator, Component, Graphics, Label, Node, Sprite, UITransform, Vec3 } from 'cc';
import { AudioMgr, SoundName } from '../Mgr/AudioMgr';
import { AssetList } from '../Global';
import { ResMgr } from '../Mgr/ResMgr';
import { UIMgr } from '../Mgr/UIMgr';
const { ccclass, property } = _decorator;

@ccclass('GameGuide')
/**
 * 游戏引导界面
 */
export class GameGuide extends Component {

    //显示区域
    @property(Node)
    public ShowContent: Node = null;
    //显示内容
    @property(Sprite)
    private PromptContent: Sprite = null;

    //显示区域
    public ShowNode1: { pos: Vec3, _rect: { width: number, height: number } }[] = [];

    public ShowIndex: number = 0;

    /**
    * 显示
    */
    public Show() {

        if (this.ShowIndex > this.ShowNode1.length - 1) {
            UIMgr.Instance.HidePop(AssetList.Pop.GAMEGUIDE);
            return;
        }

        this.PromptContent.spriteFrame = ResMgr.Instance.SpriteFrames["guide_tip" + this.ShowIndex.toString()]

        // console.log(_worldpos, _rect)

        let _worldpos: Vec3 = this.ShowNode1[this.ShowIndex].pos;
        let _rect: { width: number, height: number } = this.ShowNode1[this.ShowIndex]._rect;

        this.ShowContent.getComponent(Graphics).clear();
        this.ShowContent.getComponent(Graphics).fillRect(
            this.node.getComponent(UITransform).convertToNodeSpaceAR(_worldpos).x - _rect.width / 2,
            this.node.getComponent(UITransform).convertToNodeSpaceAR(_worldpos).y - _rect.height / 2,
            _rect.width,
            _rect.height
        );

    }

    /**
     * 点击下一步
     */
    public NextClick() {
        AudioMgr.instance.PlayEffect(SoundName.Click);
        this.ShowIndex++;
        this.Show();
    }

}


